package o;

import com.google.gson.JsonIOException;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.EnumSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;

public final class atv {
    private final aut ˊ = aut.ˎ();
    private final Map<Type, ate<?>> ˋ;

    public atv(Map<Type, ate<?>> map) {
        this.ˋ = map;
    }

    public <T> aua<T> ˎ(auv<T> o_auv_T) {
        final Type ˏ = o_auv_T.ˏ();
        Class ˋ = o_auv_T.ˋ();
        final ate o_ate = (ate) this.ˋ.get(ˏ);
        if (o_ate != null) {
            return new aua<T>(this) {
                final /* synthetic */ atv ˋ;

                public T ˋ() {
                    return o_ate.ˋ(ˏ);
                }
            };
        }
        o_ate = (ate) this.ˋ.get(ˋ);
        if (o_ate != null) {
            return new aua<T>(this) {
                final /* synthetic */ atv ˊ;

                public T ˋ() {
                    return o_ate.ˋ(ˏ);
                }
            };
        }
        aua<T> ˎ = ˎ(ˋ);
        if (ˎ != null) {
            return ˎ;
        }
        ˎ = ˏ(ˏ, ˋ);
        return ˎ == null ? ˊ(ˏ, ˋ) : ˎ;
    }

    private <T> aua<T> ˎ(Class<? super T> cls) {
        try {
            final AccessibleObject declaredConstructor = cls.getDeclaredConstructor(new Class[0]);
            if (!declaredConstructor.isAccessible()) {
                this.ˊ.ˏ(declaredConstructor);
            }
            return new aua<T>(this) {
                final /* synthetic */ atv ˎ;

                public T ˋ() {
                    try {
                        return declaredConstructor.newInstance(null);
                    } catch (Throwable e) {
                        throw new RuntimeException("Failed to invoke " + declaredConstructor + " with no args", e);
                    } catch (InvocationTargetException e2) {
                        throw new RuntimeException("Failed to invoke " + declaredConstructor + " with no args", e2.getTargetException());
                    } catch (IllegalAccessException e3) {
                        throw new AssertionError(e3);
                    }
                }
            };
        } catch (NoSuchMethodException e) {
            return null;
        }
    }

    private <T> aua<T> ˏ(final Type type, Class<? super T> cls) {
        if (Collection.class.isAssignableFrom(cls)) {
            if (SortedSet.class.isAssignableFrom(cls)) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public T ˋ() {
                        return new TreeSet();
                    }
                };
            }
            if (EnumSet.class.isAssignableFrom(cls)) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ॱ;

                    public T ˋ() {
                        if (type instanceof ParameterizedType) {
                            Type type = ((ParameterizedType) type).getActualTypeArguments()[0];
                            if (type instanceof Class) {
                                return EnumSet.noneOf((Class) type);
                            }
                            throw new JsonIOException("Invalid EnumSet type: " + type.toString());
                        }
                        throw new JsonIOException("Invalid EnumSet type: " + type.toString());
                    }
                };
            }
            if (Set.class.isAssignableFrom(cls)) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ॱ;

                    {
                        this.ॱ = r1;
                    }

                    public T ˋ() {
                        return new LinkedHashSet();
                    }
                };
            }
            if (Queue.class.isAssignableFrom(cls)) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ˋ;

                    {
                        this.ˋ = r1;
                    }

                    public T ˋ() {
                        return new ArrayDeque();
                    }
                };
            }
            return new aua<T>(this) {
                final /* synthetic */ atv ˏ;

                {
                    this.ˏ = r1;
                }

                public T ˋ() {
                    return new ArrayList();
                }
            };
        } else if (!Map.class.isAssignableFrom(cls)) {
            return null;
        } else {
            if (ConcurrentNavigableMap.class.isAssignableFrom(cls)) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ˋ;

                    {
                        this.ˋ = r1;
                    }

                    public T ˋ() {
                        return new ConcurrentSkipListMap();
                    }
                };
            }
            if (ConcurrentMap.class.isAssignableFrom(cls)) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public T ˋ() {
                        return new ConcurrentHashMap();
                    }
                };
            }
            if (SortedMap.class.isAssignableFrom(cls)) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public T ˋ() {
                        return new TreeMap();
                    }
                };
            }
            if (!(type instanceof ParameterizedType) || String.class.isAssignableFrom(auv.ˋ(((ParameterizedType) type).getActualTypeArguments()[0]).ˋ())) {
                return new aua<T>(this) {
                    final /* synthetic */ atv ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public T ˋ() {
                        return new atz();
                    }
                };
            }
            return new aua<T>(this) {
                final /* synthetic */ atv ˊ;

                {
                    this.ˊ = r1;
                }

                public T ˋ() {
                    return new LinkedHashMap();
                }
            };
        }
    }

    private <T> aua<T> ˊ(final Type type, final Class<? super T> cls) {
        return new aua<T>(this) {
            final /* synthetic */ atv ˋ;
            private final auf ˏ = auf.ˏ();

            public T ˋ() {
                try {
                    return this.ˏ.ˋ(cls);
                } catch (Throwable e) {
                    throw new RuntimeException("Unable to invoke no-args constructor for " + type + ". Registering an InstanceCreator with Gson for this type may fix this problem.", e);
                }
            }
        };
    }

    public String toString() {
        return this.ˋ.toString();
    }
}
